home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / thunderj.c < prev    next >
C/C++ Source or Header  |  2000-05-06  |  15KB  |  475 lines

  1. /***************************************************************************
  2.  
  3.     Thunderjaws
  4.  
  5.     driver by Aaron Giles
  6.  
  7. ****************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "machine/atarigen.h"
  11. #include "sndhrdw/atarijsa.h"
  12. #include "vidhrdw/generic.h"
  13.  
  14.  
  15. void thunderj_set_alpha_bank(int bank);
  16. WRITE_HANDLER( thunderj_playfieldram_w );
  17. WRITE_HANDLER( thunderj_playfield2ram_w );
  18. WRITE_HANDLER( thunderj_colorram_w );
  19.  
  20. int thunderj_vh_start(void);
  21. void thunderj_vh_stop(void);
  22. void thunderj_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  23.  
  24. void thunderj_scanline_update(int scanline);
  25.  
  26.  
  27. static UINT8 *rts_address;
  28.  
  29.  
  30.  
  31. /*************************************
  32.  *
  33.  *    Initialization
  34.  *
  35.  *************************************/
  36.  
  37. static void update_interrupts(void)
  38. {
  39.     int newstate = 0;
  40.     int newstate2 = 0;
  41.  
  42.     if (atarigen_scanline_int_state)
  43.         newstate |= 4, newstate2 |= 4;
  44.     if (atarigen_sound_int_state)
  45.         newstate |= 6;
  46.  
  47.     if (newstate)
  48.         cpu_set_irq_line(0, newstate, ASSERT_LINE);
  49.     else
  50.         cpu_set_irq_line(0, 7, CLEAR_LINE);
  51.  
  52.     if (newstate2)
  53.         cpu_set_irq_line(1, newstate2, ASSERT_LINE);
  54.     else
  55.         cpu_set_irq_line(1, 7, CLEAR_LINE);
  56. }
  57.  
  58.  
  59. static void init_machine(void)
  60. {
  61.     atarigen_eeprom_reset();
  62.     atarigen_video_control_reset();
  63.     atarigen_interrupt_reset(update_interrupts);
  64.     atarigen_scanline_timer_reset(thunderj_scanline_update, 8);
  65.     atarijsa_reset();
  66. }
  67.  
  68.  
  69.  
  70. /*************************************
  71.  *
  72.  *    I/O handling
  73.  *
  74.  *************************************/
  75.  
  76. static READ_HANDLER( special_port2_r )
  77. {
  78.     int result = input_port_2_r(offset);
  79.  
  80.     if (atarigen_sound_to_cpu_ready) result ^= 0x0004;
  81.     if (atarigen_cpu_to_sound_ready) result ^= 0x0008;
  82.     result ^= 0x0010;
  83.  
  84.     return result;
  85. }
  86.  
  87.  
  88. static WRITE_HANDLER( latch_w )
  89. {
  90.     /* reset extra CPU */
  91.     if (!(data & 0x00ff0000))
  92.     {
  93.         /* 0 means hold CPU 2's reset low */
  94.         if (data & 1)
  95.             cpu_set_reset_line(1,CLEAR_LINE);
  96.         else
  97.             cpu_set_reset_line(1,ASSERT_LINE);
  98.  
  99.         /* bits 2-5 are the alpha bank */
  100.         thunderj_set_alpha_bank((data >> 2) & 7);
  101.     }
  102. }
  103.  
  104.  
  105.  
  106. /*************************************
  107.  *
  108.  *    Video Controller Hack
  109.  *
  110.  *************************************/
  111.  
  112. READ_HANDLER( thunderj_video_control_r )
  113. {
  114.     /* Sigh. CPU #1 reads the video controller register twice per frame, once at
  115.        the beginning of interrupt and once near the end. It stores these values in a
  116.        table starting at $163484. CPU #2 periodically looks at this table to make
  117.        sure that it is getting interrupts at the appropriate times, and that the
  118.        VBLANK bit is set appropriately. Unfortunately, due to all the cpu_yield()
  119.        calls we make to synchronize the two CPUs, we occasionally get out of time
  120.        and generate the interrupt outside of the tight tolerances CPU #2 expects.
  121.  
  122.        So we fake it. Returning scanlines $f5 and $f7 alternately provides the
  123.        correct answer that causes CPU #2 to be happy and not aggressively trash
  124.        memory (which is what it does if this interrupt test fails -- see the code
  125.        at $1E56 to see!) */
  126.  
  127.     /* Use these lines to detect when things go south:
  128.  
  129.     if (cpu_readmem24bew_word(0x163482) > 0xfff)
  130.         printf("You're screwed!");*/
  131.  
  132.     return atarigen_video_control_r(offset);
  133. }
  134.  
  135.  
  136.  
  137. /*************************************
  138.  *
  139.  *    Main CPU memory handlers
  140.  *
  141.  *************************************/
  142.  
  143. static struct MemoryReadAddress main_readmem[] =
  144. {
  145.     { 0x000000, 0x09ffff, MRA_ROM },
  146.     { 0x0e0000, 0x0e0fff, atarigen_eeprom_r },
  147.     { 0x160000, 0x16ffff, MRA_BANK1 },
  148.     { 0x260000, 0x26000f, input_port_0_r },
  149.     { 0x260010, 0x260011, input_port_1_r },
  150.     { 0x260012, 0x260013, special_port2_r },
  151.     { 0x260030, 0x260031, atarigen_sound_r },
  152.     { 0x3e0000, 0x3e0fff, paletteram_word_r },
  153.     { 0x3effc0, 0x3effff, thunderj_video_control_r },
  154.     { 0x3f0000, 0x3f5fff, MRA_BANK3 },
  155.     { 0x3f6000, 0x3f7fff, MRA_BANK4 },
  156.     { 0x3f8000, 0x3f8fff, MRA_BANK5 },
  157.     { 0x3f9000, 0x3fffff, MRA_BANK6 },
  158.     { 0x800000, 0x800001, MRA_BANK7 },
  159.     { -1 }  /* end of table */
  160. };
  161.  
  162.  
  163. static struct MemoryWriteAddress main_writemem[] =
  164. {
  165.     { 0x000000, 0x09ffff, MWA_ROM },
  166.     { 0x0e0000, 0x0e0fff, atarigen_eeprom_w, &atarigen_eeprom, &atarigen_eeprom_size },
  167.     { 0x160000, 0x16ffff, MWA_BANK1 },
  168.     { 0x1f0000, 0x1fffff, atarigen_eeprom_enable_w },
  169.     { 0x2e0000, 0x2e0001, watchdog_reset_w },
  170.     { 0x360010, 0x360011, latch_w },
  171.     { 0x360020, 0x360021, atarigen_sound_reset_w },
  172.     { 0x360030, 0x360031, atarigen_sound_w },
  173.     { 0x3e0000, 0x3e0fff, atarigen_666_paletteram_w, &paletteram },
  174.     { 0x3effc0, 0x3effff, atarigen_video_control_w, &atarigen_video_control_data },
  175.     { 0x3f0000, 0x3f1fff, thunderj_playfield2ram_w, &atarigen_playfield2ram, &atarigen_playfield2ram_size },
  176.     { 0x3f2000, 0x3f3fff, thunderj_playfieldram_w, &atarigen_playfieldram, &atarigen_playfieldram_size },
  177.     { 0x3f4000, 0x3f5fff, thunderj_colorram_w, &atarigen_playfieldram_color },
  178.     { 0x3f6000, 0x3f7fff, MWA_BANK4, &atarigen_spriteram, &atarigen_spriteram_size },
  179.     { 0x3f8000, 0x3f8fff, MWA_BANK5, &atarigen_alpharam, &atarigen_alpharam_size },
  180.     { 0x3f9000, 0x3fffff, MWA_BANK6 },
  181.     { 0x800000, 0x800001, MWA_BANK7, &rts_address },
  182.     { -1 }  /* end of table */
  183. };
  184.  
  185.  
  186.  
  187. /*************************************
  188.  *
  189.  *    Extra CPU memory handlers
  190.  *
  191.  *************************************/
  192.  
  193. static struct MemoryReadAddress extra_readmem[] =
  194. {
  195.     { 0x000000, 0x03ffff, MRA_ROM },
  196.     { 0x060000, 0x07ffff, MRA_ROM },
  197.     { 0x160000, 0x16ffff, MRA_BANK1 },
  198.     { 0x260000, 0x26000f, input_port_0_r },
  199.     { 0x260010, 0x260011, input_port_1_r },
  200.     { 0x260012, 0x260013, special_port2_r },
  201.     { 0x260030, 0x260031, atarigen_sound_r },
  202.     { -1 }  /* end of table */
  203. };
  204.  
  205.  
  206. static struct MemoryWriteAddress extra_writemem[] =
  207. {
  208.     { 0x000000, 0x03ffff, MWA_ROM },
  209.     { 0x060000, 0x07ffff, MWA_ROM },
  210.     { 0x160000, 0x16ffff, MWA_BANK1 },
  211.     { 0x360000, 0x360001, atarigen_video_int_ack_w },
  212.     { 0x360010, 0x360011, latch_w },
  213.     { 0x360020, 0x360021, atarigen_sound_reset_w },
  214.     { 0x360030, 0x360031, atarigen_sound_w },
  215.     { -1 }  /* end of table */
  216. };
  217.  
  218.  
  219.  
  220. /*************************************
  221.  *
  222.  *    Port definitions
  223.  *
  224.  *************************************/
  225.  
  226. INPUT_PORTS_START( thunderj )
  227.     PORT_START        /* 260000 */
  228.     PORT_BIT( 0xffff, IP_ACTIVE_LOW, IPT_UNUSED )
  229.  
  230.     PORT_START        /* 260010 */
  231.     PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )
  232.     PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_START1 )
  233.     PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  234.     PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  235.     PORT_BIT( 0x0c00, IP_ACTIVE_LOW, IPT_UNUSED )
  236.     PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER1 )
  237.     PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_PLAYER1 )
  238.     PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_PLAYER1 )
  239.     PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_PLAYER1 )
  240.  
  241.     PORT_START        /* 260012 */
  242.     PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_VBLANK )
  243.     PORT_SERVICE( 0x0002, IP_ACTIVE_LOW )
  244.     PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNUSED )    /* Input buffer full (@260030) */
  245.     PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNUSED )    /* Output buffer full (@360030) */
  246.     PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_UNUSED )
  247.     PORT_BIT( 0x00e0, IP_ACTIVE_LOW, IPT_UNUSED )
  248.     PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_START2 )
  249.     PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  250.     PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  251.     PORT_BIT( 0x0c00, IP_ACTIVE_LOW, IPT_UNUSED )
  252.     PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER2 )
  253.     PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_PLAYER2 )
  254.     PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_PLAYER2 )
  255.     PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_PLAYER2 )
  256.  
  257.     JSA_II_PORT        /* audio board port */
  258. INPUT_PORTS_END
  259.  
  260.  
  261.  
  262. /*************************************
  263.  *
  264.  *    Graphics definitions
  265.  *
  266.  *************************************/
  267.  
  268. static struct GfxLayout anlayout =
  269. {
  270.     8,8,    /* 8*8 chars */
  271.     4096,    /* 4096 chars */
  272.     2,        /* 2 bits per pixel */
  273.     { 0, 4 },
  274.     { 0, 1, 2, 3, 8, 9, 10, 11 },
  275.     { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 },
  276.     8*16    /* every char takes 16 consecutive bytes */
  277. };
  278.  
  279.  
  280. static struct GfxLayout pfmolayout =
  281. {
  282.     8,8,    /* 8*8 sprites */
  283.     32768,    /* 32768 of them */
  284.     4,        /* 4 bits per pixel */
  285.     { 3*8*0x40000, 2*8*0x40000, 1*8*0x40000, 0*8*0x40000 },
  286.     { 0, 1, 2, 3, 4, 5, 6, 7 },
  287.     { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
  288.     8*8    /* every sprite takes 8 consecutive bytes */
  289. };
  290.  
  291.  
  292. static struct GfxDecodeInfo gfxdecodeinfo[] =
  293. {
  294.     { REGION_GFX1, 0, &pfmolayout,  512,  96 },    /* sprites & playfield */
  295.     { REGION_GFX2, 0, &pfmolayout,  256, 112 },    /* sprites & playfield */
  296.     { REGION_GFX3, 0, &anlayout,      0, 512 },    /* characters 8x8 */
  297.     { -1 } /* end of array */
  298. };
  299.  
  300.  
  301.  
  302. /*************************************
  303.  *
  304.  *    Machine driver
  305.  *
  306.  *************************************/
  307.  
  308. static struct MachineDriver machine_driver_thunderj =
  309. {
  310.     /* basic machine hardware */
  311.     {
  312.         {
  313.             CPU_M68000,        /* verified */
  314.             ATARI_CLOCK_14MHz/2,
  315.             main_readmem,main_writemem,0,0,
  316.             ignore_interrupt,1
  317.         },
  318.         {
  319.             CPU_M68000,        /* verified */
  320.             ATARI_CLOCK_14MHz/2,
  321.             extra_readmem,extra_writemem,0,0,
  322.             ignore_interrupt,1
  323.         },
  324.         JSA_II_CPU
  325.     },
  326.     60, DEFAULT_REAL_60HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  327.     100,
  328.     init_machine,
  329.  
  330.     /* video hardware */
  331.     42*8, 30*8, { 0*8, 42*8-1, 0*8, 30*8-1 },
  332.     gfxdecodeinfo,
  333.     2048, 2048,
  334.     0,
  335.  
  336.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE | VIDEO_UPDATE_BEFORE_VBLANK,
  337.     0,
  338.     thunderj_vh_start,
  339.     thunderj_vh_stop,
  340.     thunderj_vh_screenrefresh,
  341.  
  342.     /* sound hardware */
  343.     JSA_II_MONO(REGION_SOUND1),
  344.  
  345.     atarigen_nvram_handler
  346. };
  347.  
  348.  
  349.  
  350. /*************************************
  351.  *
  352.  *    ROM decoding
  353.  *
  354.  *************************************/
  355.  
  356. static void rom_decode(void)
  357. {
  358.     int i;
  359.  
  360.     /* invert the graphics bits on the playfield and motion objects */
  361.     for (i = 0; i < memory_region_length(REGION_GFX1); i++)
  362.         memory_region(REGION_GFX1)[i] ^= 0xff;
  363.     for (i = 0; i < memory_region_length(REGION_GFX2); i++)
  364.         memory_region(REGION_GFX2)[i] ^= 0xff;
  365.  
  366.     /* copy the shared ROM from region 0 to region 1 */
  367.     memcpy(&memory_region(REGION_CPU2)[0x60000], &memory_region(REGION_CPU1)[0x60000], 0x20000);
  368. }
  369.  
  370.  
  371.  
  372. /*************************************
  373.  *
  374.  *    Driver initialization
  375.  *
  376.  *************************************/
  377.  
  378. static void init_thunderj(void)
  379. {
  380.     atarigen_eeprom_default = NULL;
  381.  
  382.     atarijsa_init(2, 3, 2, 0x0002);
  383.  
  384.     /* speed up the 6502 */
  385.     atarigen_init_6502_speedup(2, 0x4159, 0x4171);
  386.  
  387.     /* it looks like they jsr to $800000 as some kind of protection */
  388.     /* put an RTS there so we don't die */
  389.     WRITE_WORD(rts_address, 0x4E75);
  390.  
  391.     /* display messages */
  392.     atarigen_show_sound_message();
  393.  
  394.     rom_decode();
  395. }
  396.  
  397.  
  398.  
  399. /*************************************
  400.  *
  401.  *    ROM definition(s)
  402.  *
  403.  *************************************/
  404.  
  405. ROM_START( thunderj )
  406.     ROM_REGION( 0xa0000, REGION_CPU1 )    /* 10*64k for 68000 code */
  407.     ROM_LOAD_EVEN( "2001.14e",   0x00000, 0x10000, 0xf6a71532 )
  408.     ROM_LOAD_ODD ( "2002.14c",   0x00000, 0x10000, 0x173ec10d )
  409.     ROM_LOAD_EVEN( "2003.15e",   0x20000, 0x10000, 0x6e155469 )
  410.     ROM_LOAD_ODD ( "2004.15c",   0x20000, 0x10000, 0xe9ff1e42 )
  411.     ROM_LOAD_EVEN( "2005.16e",   0x40000, 0x10000, 0xa40242e7 )
  412.     ROM_LOAD_ODD ( "2006.16c",   0x40000, 0x10000, 0xaa18b94c )
  413.     ROM_LOAD_EVEN( "1005.15h",   0x60000, 0x10000, 0x05474ebb )
  414.     ROM_LOAD_ODD ( "1010.16h",   0x60000, 0x10000, 0xccff21c8 )
  415.     ROM_LOAD_EVEN( "1007.17e",   0x80000, 0x10000, 0x9c2a8aba )
  416.     ROM_LOAD_ODD ( "1008.17c",   0x80000, 0x10000, 0x22109d16 )
  417.  
  418.     ROM_REGION( 0x80000, REGION_CPU2 )    /* 8*64k for 68000 code */
  419.     ROM_LOAD_EVEN( "1011.17l",   0x00000, 0x10000, 0xbbbbca45 )
  420.     ROM_LOAD_ODD ( "1012.17n",   0x00000, 0x10000, 0x53e5e638 )
  421.  
  422.     ROM_REGION( 0x14000, REGION_CPU3 )    /* 64k + 16k for 6502 code */
  423.     ROM_LOAD( "tjw65snd.bin",  0x10000, 0x4000, 0xd8feb7fb )
  424.     ROM_CONTINUE(              0x04000, 0xc000 )
  425.  
  426.     ROM_REGION( 0x100000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  427.     ROM_LOAD( "1021.5s",   0x000000, 0x10000, 0xd8432766 )    /* graphics, plane 0 */
  428.     ROM_LOAD( "1025.5r",   0x010000, 0x10000, 0x839feed5 )
  429.     ROM_LOAD( "1029.3p",   0x020000, 0x10000, 0xfa887662 )
  430.     ROM_LOAD( "1033.6p",   0x030000, 0x10000, 0x2addda79 )
  431.     ROM_LOAD( "1022.9s",   0x040000, 0x10000, 0xdcf50371 )    /* graphics, plane 1 */
  432.     ROM_LOAD( "1026.9r",   0x050000, 0x10000, 0x216e72c8 )
  433.     ROM_LOAD( "1030.10s",  0x060000, 0x10000, 0xdc51f606 )
  434.     ROM_LOAD( "1034.10r",  0x070000, 0x10000, 0xf8e35516 )
  435.     ROM_LOAD( "1023.13s",  0x080000, 0x10000, 0xb6dc3f13 )    /* graphics, plane 2 */
  436.     ROM_LOAD( "1027.13r",  0x090000, 0x10000, 0x621cc2ce )
  437.     ROM_LOAD( "1031.14s",  0x0a0000, 0x10000, 0x4682ceb5 )
  438.     ROM_LOAD( "1035.14r",  0x0b0000, 0x10000, 0x7a0e1b9e )
  439.     ROM_LOAD( "1024.17s",  0x0c0000, 0x10000, 0xd84452b5 )    /* graphics, plane 3 */
  440.     ROM_LOAD( "1028.17r",  0x0d0000, 0x10000, 0x0cc20245 )
  441.     ROM_LOAD( "1032.14p",  0x0e0000, 0x10000, 0xf639161a )
  442.     ROM_LOAD( "1036.16p",  0x0f0000, 0x10000, 0xb342443d )
  443.  
  444.     ROM_REGION( 0x100000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  445.     ROM_LOAD( "1037.2s",   0x000000, 0x10000, 0x07addba6 )
  446.     ROM_LOAD( "1041.2r",   0x010000, 0x10000, 0x1e9c29e4 )
  447.     ROM_LOAD( "1045.34s",  0x020000, 0x10000, 0xe7235876 )
  448.     ROM_LOAD( "1049.34r",  0x030000, 0x10000, 0xa6eb8265 )
  449.     ROM_LOAD( "1038.6s",   0x040000, 0x10000, 0x2ea543f9 )
  450.     ROM_LOAD( "1042.6r",   0x050000, 0x10000, 0xefabdc2b )
  451.     ROM_LOAD( "1046.7s",   0x060000, 0x10000, 0x6692151f )
  452.     ROM_LOAD( "1050.7r",   0x070000, 0x10000, 0xad7bb5f3 )
  453.     ROM_LOAD( "1039.11s",  0x080000, 0x10000, 0xcb563a40 )
  454.     ROM_LOAD( "1043.11r",  0x090000, 0x10000, 0xb7565eee )
  455.     ROM_LOAD( "1047.12s",  0x0a0000, 0x10000, 0x60877136 )
  456.     ROM_LOAD( "1051.12r",  0x0b0000, 0x10000, 0xd4715ff0 )
  457.     ROM_LOAD( "1040.15s",  0x0c0000, 0x10000, 0x6e910fc2 )
  458.     ROM_LOAD( "1044.15r",  0x0d0000, 0x10000, 0xff67a17a )
  459.     ROM_LOAD( "1048.16s",  0x0e0000, 0x10000, 0x200d45b3 )
  460.     ROM_LOAD( "1052.16r",  0x0f0000, 0x10000, 0x74711ef1 )
  461.  
  462.     ROM_REGION( 0x010000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  463.     ROM_LOAD( "1020.4m",   0x000000, 0x10000, 0x65470354 )    /* alphanumerics */
  464.  
  465.     ROM_REGION( 0x40000, REGION_SOUND1 )    /* 256k for ADPCM */
  466.     ROM_LOAD( "tj1016.bin",  0x00000, 0x10000, 0xc10bdf73 )
  467.     ROM_LOAD( "tj1017.bin",  0x10000, 0x10000, 0x4e5e25e8 )
  468.     ROM_LOAD( "tj1018.bin",  0x20000, 0x10000, 0xec81895d )
  469.     ROM_LOAD( "tj1019.bin",  0x30000, 0x10000, 0xa4009037 )
  470. ROM_END
  471.  
  472.  
  473.  
  474. GAME( 1990, thunderj, 0, thunderj, thunderj, thunderj, ROT0, "Atari Games", "ThunderJaws" )
  475.